/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package controller;

import java.io.IOException;
import java.util.List;
import java.util.Scanner;

import model.Camping;
import model.ExpressionGenerator;

/**
 * class for executing exercises 1 and 2 for assignment 6. Exercise 1: generating all possible expressions (using a fixed set of numbers and operations) that result in a given goal Exercise 2: solving a Camping (Tentje-Boompje) puzzle,
 * places tents for a number of examples
 * 
 * @author Pieter Koopman
 * @author Karen Berntsen (s0815799)
 * @author Erik Stens (s0615374)
 */
public class AD_exercise_6_old {
	public static void main(String[] args) {
		new AD_exercise_6_old();
	}
	
	/**
	 * Creates campings for example files; prints the camping and places tents
	 */
	public AD_exercise_6_old() {
		exercise1();
		
		System.out.println();
		
		exercise2();
	}
	
	private void exercise1() {
		ExpressionGenerator expressionsGenerator = new ExpressionGenerator(new int[] { -1, 1, 2, 3, 4, 5, 6, 7, 11, 13 });
		
		Scanner scan = new Scanner(System.in);
		List<String> solutions;
		System.out.print("Give a number (0 to stop): ");
		for (int doel = scan.nextInt(); doel != 0; doel = scan.nextInt()) {
			solutions = expressionsGenerator.search(doel);
			for (String solution : solutions) {
				System.out.println(solution);
			}
			System.out.print("Give a number (0 to stop): ");
		}
	}
	
	private void exercise2() {
		String rootDir = "./resources/";
		String fileNames[] = { "c.txt", "c0.txt", "c1.txt", "c2.txt", "c3.txt", "c4.txt", "c5.txt", "c6.txt", "c7.txt" };
		// String fileNames[] = { "c.txt" };
		for (String fileName : fileNames) {
			try {
				Camping camping = new Camping(rootDir + fileName);
				System.out.println(fileName + ":");
				System.out.println(camping);
				camping.placeTents();
			} catch (IOException e) {
				System.out.println("Unable to read file '" + rootDir + fileName + "': " + e.getMessage());
			}
		}
	}
}
